// -----------------------------------------------------------------------
//  <copyright file="IResourceService.cs" company="LiuliuSoft">
//      Copyright (c) 2022-2025 DaprPlus. All rights reserved.
//  </copyright>
//  <site>https://dapr.plus</site>
//  <last-editor>郭明锋</last-editor>
//  <last-date>2025/1/8 18:08</last-date>
// -----------------------------------------------------------------------

using DaprPlus.Authorization.Application.Commands;
using DaprPlus.Filters;

namespace DaprPlus.Authorization.Domain;

/// <summary>
/// 定义资源领域服务
/// </summary>
public interface IResourceService
{
    /// <summary>
    /// 创建资源
    /// </summary>
    /// <param name="resource">提取的资源信息</param>
    /// <param name="token"></param>
    /// <returns></returns>
    Task<ApiResult> CreateResourceAsync(IResource resource, CancellationToken token);

    /// <summary>
    /// 更新资源
    /// </summary>
    /// <param name="resource">提取的资源信息</param>
    /// <param name="sync">是否初始化同步，否则为后台更新</param>
    /// <param name="token"></param>
    /// <returns></returns>
    Task<ApiResult> UpdateResourceAsync(IResource resource, bool sync, CancellationToken token);

    /// <summary>
    /// 删除指定Id的资源
    /// </summary>
    /// <param name="id">资源Id</param>
    /// <param name="token"></param>
    /// <returns></returns>
    Task<ApiResult> DeleteResourceAsync(long id, CancellationToken token = default);

    /// <summary>
    /// 删除指定服务中的指定类型的所有资源
    /// </summary>
    /// <param name="serviceName">服务名称</param>
    /// <param name="type">资源类型</param>
    /// <param name="token"></param>
    /// <returns></returns>
    Task<ApiResult> DeleteResourceAsync(string serviceName, ResourceType type, CancellationToken token = default);

    /// <summary>
    /// 设置角色资源
    /// </summary>
    /// <param name="roleId">角色Id</param>
    /// <param name="dtos">角色资源信息</param>
    /// <param name="token"></param>
    /// <returns></returns>
    Task<ApiResult<IRoleResource[]>> SetRoleResourceAsync(long roleId, RoleResourceInDto[] dtos, CancellationToken token);

    /// <summary>
    /// 设置角色资源的过滤组
    /// </summary>
    /// <param name="resourceId">资源Id</param>
    /// <param name="roleId">角色Id</param>
    /// <param name="filterGroups">资源数据过滤条件组</param>
    /// <param name="token"></param>
    /// <returns></returns>
    Task<ApiResult<IRoleResource>> SetFilterGroupsAsync(long resourceId, long roleId, IDictionary<string, FilterGroup> filterGroups, CancellationToken token);

    /// <summary>
    /// 移除角色资源
    /// </summary>
    /// <param name="roleId">角色Id</param>
    /// <param name="resourceIds">资源Id</param>
    /// <param name="token"></param>
    /// <returns></returns>
    Task<ApiResult> RemoveRoleResourceAsync(long roleId, long[] resourceIds, CancellationToken token);
}
